/**
 * 长度最小的子数组
 * https://leetcode.cn/problems/2VG8Kg/description/
 */
class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0, right = 0, n = nums.length;
        int ret = Integer.MAX_VALUE;
        int tmp = 0;
        while(right < n) {
            //进窗口
            tmp += nums[right++];
            //判断
            while(tmp >= target) {
                ret = Math.min(ret, right - left);
                //出窗口
                tmp -= nums[left++];
            }
        }
        return ret == Integer.MAX_VALUE ? 0 : ret;
    }
}